package com.hua.Thread.ThreadPool;

import com.sun.corba.se.spi.orbutil.threadpool.Work;
import javafx.concurrent.Worker;

import java.util.concurrent.CountDownLatch;

/**
 * @author: _hua
 * @created: 2019/3/10.
 * @updater:
 * @description:
 */
public class WorkerThread implements Runnable {

    private String command;
    CountDownLatch latch;

    public WorkerThread(String s){
        this.command=s;
    }
    public WorkerThread(String s , CountDownLatch latch){
        this.command=s;
        this.latch=latch;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+" Start. Command = "+command);
        processCommand();
        System.out.println(Thread.currentThread().getName()+" End.");
        if(latch != null) {
            latch.countDown();
        }
    }

    private void processCommand() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString(){
        return this.command;
    }
}